/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jaotwinker;
import java.io.File;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
/**
 *
 * @author Grayson
 */
public class ExcludedItems {
    
    ArrayList ids;
    
    public ExcludedItems(String filename) {
        ids = new ArrayList();
        List<String> items;
        byte[] buffer = new byte[(int) new File(filename).length()];
        BufferedInputStream f = null;
        try {
            f = new BufferedInputStream(new FileInputStream(filename));
            f.read(buffer);
        } catch (IOException e) { e.printStackTrace();
        } finally {
            if (f != null) try { f.close(); } catch (IOException ignored) { }
        }
        String result = new String(buffer);
        items = Arrays.asList(result.split(","));
        for(int i=0;i<items.size();i++) {
            ids.add(Integer.parseInt(items.get(i)));
        }
    }
    
    public void add(int id) {
        if(!ids.contains(id)) ids.add(id);
    }

    public void save(String filename) {
        String output = "";
        for(int i=0;i<ids.size();i++) {
            output += String.valueOf(ids.get(i));
            output += ",";
        }
        try {
            BufferedWriter out = new BufferedWriter(new FileWriter(filename));
            out.write(output);
            out.close();
        }
        catch (IOException e) { e.printStackTrace(); }
    }
}
